import React from "react"
import useUnmount from "../../hooks/useUnmount.ts"
import { useState } from "react"

const Child = () => {
  useUnmount(() => {
    console.log("卸载了，unmount")
  })

  return <div>我是子组件</div>
}

const TryUseUnmount = () => {
  const [flag, setFlag] = useState(true)

  return (
    <>
      <button onClick={() => setFlag(!flag)}>点击切换</button>
      {flag && <Child />}
    </>
  )
}

export default TryUseUnmount
